package com.woniu.woniuk16.controller;


import com.woniu.woniuk16.dto.StudentDto;
import com.woniu.woniuk16.dto.StusDto;
import com.woniu.woniuk16.exception.stu.StudentException;
import com.woniu.woniuk16.model.Result;

import com.woniu.woniuk16.param.student.AddStudentParam;
import com.woniu.woniuk16.param.student.GetStusParam;
import com.woniu.woniuk16.service.WoniuStudentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author tiangle
 * @since 2021-12-16
 */
@RestController
@RequestMapping("/woniuStudent")
public class WoniuStudentController {
    @Autowired
    private WoniuStudentService woniuStudentService;

    @PostMapping("/like")
    public Result getStudents(@RequestBody GetStusParam getStusParam){
        StusDto stusDto = woniuStudentService.selStudent(getStusParam);
        return Result.getInstance(stusDto);
    }

    @PostMapping("save")
    public Result addStudent(@RequestBody AddStudentParam addStudentParam) throws StudentException {
        boolean b = woniuStudentService.saveStudent(addStudentParam);
        return Result.getInstance(null).setMessage("添加成功");
    }

    @GetMapping("/class/{classId}")
    public Result getStudentsByClass(@PathVariable Integer classId) throws StudentException {
        List<StudentDto> stusByClass = woniuStudentService.getStusByClass(classId);
        return Result.getInstance(stusByClass);
    }
}

